from launch import LaunchDescription
from launch_ros.actions import Node
import launch

# 启动文件，启动 turtlesim 节点和 spawn 节点


def generate_launch_description():

    turtle = Node(
        package='turtlesim',
        executable='turtlesim_node',
        name="turtle1"
    )

    spawn = Node(
        package='cpp05_exercise',
        executable='c01_spawn',
        parameters=[{'turtle_name': 't2'}]
    )

    # 动态广播
    broadcaster1 = Node(
        package='cpp05_exercise',
        executable='c02_broadcaster',
        name='broad1'
    )

    broadcaster2 = Node(
        package='cpp05_exercise',
        executable='c02_broadcaster',
        name='broad2',
        parameters=[{'turtle': 't2'}]
    )

    # 监听
    listener = Node(
        package='cpp05_exercise',
        executable='c03_listener',
        parameters=[{'target_frame': 't2', "source_frame": "turtle1"}]
    )

    return LaunchDescription([turtle, spawn, broadcaster1, broadcaster2, listener])
